<?php
class UsersController extends AppController {
    var $name='Users';
    public $helpers=array('Html','Form');
    public $components=array('Session');
    
    public function index(){
        $parametros=array('order'=>'apellido asc');
        $this->set('usuarios',$this->User->find('all',$parametros));
                
        
        
    }
    
    public function insertar(){
        if ($this->request->is('post')):
            if($this->User->save($this->request->data)):
                $this->Session->setFlash('Uauario guardado');
                $this->redirect(array('action'=>'index'));
            endif;
        endif;
           
    }
    
    
    public function editar($id=null){
        $this->User->id=$id;
        if($this->request->is('get')):
            $this->request->data=$this->User->read();
        else:
            if($this->User->save($this->request->data)):
                $this->Session->setFlash('Usuario guardado');
                $this->redirect(array('action'=>'index'));
            else:
                $this->Session->setFlash('No se pudo guardar');
            endif;
        endif;
        
        
    }
    
    public function eliminar($id){
        if($this->request->is('get')):
            throw new MethodNotAllowedException();
        else:
            if($this->User->delete($id)):
                $this->Session->setFlash('Usuario Eliminado');
                $this->redirect(array('action'=>'index'));
            endif;
        endif;
        
        
    }

}

?>
